package com.baiyue.controller;


import com.baiyue.model.productInfo.ProductInfoDataRequest;
import com.baiyue.model.productInfo.ProductInfoDataResponse;
import com.baiyue.result.Result;
import com.baiyue.service.ProductInfoService;
import com.baomidou.mybatisplus.plugins.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 * @author 伍波
 * @date 2024-06-13
 */
@RestController
@RequestMapping("/api/productInfo")
public class ProductInfoController {
    @Autowired
    private ProductInfoService productInfoService;

    @PostMapping("/add")
    public Result<Boolean> insertProductInfo(@RequestBody ProductInfoDataRequest request) {
        productInfoService.insert(request);
        return Result.success(true);
    }

    @PostMapping("/list")
    public Result<Page<ProductInfoDataResponse>> findByPage(@RequestBody ProductInfoDataRequest request) {
        return Result.success(productInfoService.findByPage(request));
    }

    @PostMapping("/byId")
    public Result<ProductInfoDataResponse> findById(@RequestBody ProductInfoDataRequest request) {
        return Result.success(productInfoService.findById(request));
    }

    @PostMapping("/delete")
    public Result<Boolean> deleteByIds(@RequestBody ProductInfoDataRequest request) {
        return Result.success(productInfoService.deleteByIds(request));
    }

    @PostMapping("/update")
    public Result<Boolean> updateById(@RequestBody ProductInfoDataRequest request) {
        productInfoService.updateProductInfo(request);
        return Result.success(true);
    }

    @PostMapping("/all")
    public Result<List<ProductInfoDataResponse>> findAll(@RequestBody ProductInfoDataRequest request) {
        return Result.success(productInfoService.findAllNoPage(request));
    }
}

